package com.jdk.demo.thread.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

// 当两个CompletionStage都执行完成后，把结果一块交给thenAcceptBoth来进行消耗
public class ThenAcceptBoth {

	public static void main(String[] args) throws InterruptedException {
		CompletableFuture<String> future1 = CompletableFuture.supplyAsync(new Supplier<String>() {
	        @Override
	        public String get() {
	            return "hello1";
	        }
	    });
	    CompletableFuture<String> future2 = CompletableFuture.supplyAsync(new Supplier<String>() {
	        @Override
	        public String get() {
	            return "hello2";
	        }
	    });
	    future1.thenAcceptBoth(future2, new BiConsumer<String, String>() {
	        @Override
	        public void accept(String t, String u) {
	            System.out.println("f1="+t+";f2="+u+";");
	        }
	    });
	    Thread.sleep(10000000);
	}

}
